package com.ljx.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ljx.R;
import com.ljx.pojo.EduCourse;
import com.ljx.pojo.EduTeacher;
import com.ljx.service.impl.EduCourseServiceImpl;
import com.ljx.service.impl.EduTeacherServiceImpl;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.ref.WeakReference;
import java.util.List;

/**
 * @author 李加喜
 * @date 2020/9/28 0028 22:19
 * @Email 1129071273@qq.com
 */
@Api(description = "实现了对前台显示界面的操作")
@RestController
@RequestMapping("/eduservice/indexfront")
@CrossOrigin
public class IndexFrontController {
    //查询热门课程  就是课程表里面view_count排行前8的数据
    @Autowired
    private EduTeacherServiceImpl teacherService;
    @Autowired
    private EduCourseServiceImpl courseService;
    //查询热门的课程与优秀讲师
    @GetMapping("/getOrder")
    @Cacheable(key = "'TCList'",value = "teacherCourseList")
    //这里最好将方法分为两个因为这里返回的不是集合是json数据
    public R getOrderCourse(){
        //查询排行前8的热门课程
        QueryWrapper<EduCourse> wrapperCourse = new QueryWrapper<>();
        wrapperCourse.orderByDesc("view_count");
        wrapperCourse.last("limit 8");
        List<EduCourse> list = courseService.list(wrapperCourse);
        //查询排行前4的热门的教师
        QueryWrapper<EduTeacher> wrapperTeacher = new QueryWrapper<>();
        wrapperTeacher.orderByDesc("sort");
        wrapperTeacher.last("limit 4");
        //查询课程里面排行前4的教师
        List<EduTeacher> teachers = teacherService.list(wrapperTeacher);
        return R.ok().data("courseList",list).data("teacherList",teachers);
    }

}
